package com.bckj.freshnow.order.trade.ons.listener;

import com.aliyun.openservices.ons.api.Action;
import com.aliyun.openservices.ons.api.ConsumeContext;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.MessageListener;
import com.bckj.fastboot.core.jackson.JsonUtils;
import com.bckj.fastboot.mq.ons.OnsListener;
import com.bckj.freshnow.common.constant.TradeOrderConstants;
import com.bckj.freshnow.common.constant.TradeOrderMQConstants;
import com.bckj.freshnow.order.model.TradeStatusChangeMsg;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RequiredArgsConstructor
@OnsListener(topic = TradeOrderMQConstants.TOPIC_STATUS_CHANGE)
public class TradeStatusChangeListener implements MessageListener {
    @Override
    public Action consume(Message message, ConsumeContext consumeContext) {
        String body = new String(message.getBody());
        log.info("收到订单状态变更消息: {}", body);
        //消费状态变更
        TradeStatusChangeMsg msg = JsonUtils.toBean(body, TradeStatusChangeMsg.class);
        switch (msg.getEvent()) {
            case TradeOrderConstants.EVENT_PAY_SUCCESS -> {

            }
        }
        return Action.CommitMessage;
    }
}
